package com.atguigu.cmsservice.controller;

import com.atguigu.annotation.WebLog;
import com.atguigu.cmsservice.entity.CrmBanner;
import com.atguigu.cmsservice.service.CrmBannerService;
import com.atguigu.commonutils.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author chenyeqing
 * @Date 2022/3/24 22:58
 */
@RestController
@RequestMapping("/cmsservice/bannerFront")
@CrossOrigin
public class BannerFrontController {

    @Autowired
    private CrmBannerService bannerService;

    /**
     * 首页数据添加 redis 缓存
     *
     * @return
     */
    @WebLog("查询所有banner")
    @GetMapping("listBanner")
    @Cacheable(value = "banner", key = "'selectIndexList'")
    public R listBanner() {
        List<CrmBanner> list = bannerService.selectAllBanner();
        return R.ok().data("items", list);
    }

    @GetMapping("clearBanner")
    @CacheEvict(value = "banner", key = "'selectIndexList'")
    public R clearBanner() {
        return R.ok();
    }

}
